package sql;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
/**
 * this class validate user login
 * @author Ron Shenkerman
 * @author Ivan Onyshchenko
 */
public class Check_login {
	ArrayList<String> user = new ArrayList<String>();
	
	/**
	 * check login details
	 * @param name
	 * @param pass
	 * @return 1-manager 
	 * @return 2-secretary 
	 * @return 3-stokekeeper
	 * @throws SQLException
	 */
	public ArrayList<String>  checklogin(String name , String pass) throws SQLException
	{
		
		try 
		{

			System.out.println("checking login information");
			System.out.println("name:"+name +"pass:" +pass);
			Statement stmt;
			
			SQLConnection conn = new  SQLConnection();
			stmt = conn.getConnection().createStatement();
			
			ResultSet rs= stmt.executeQuery("SELECT * FROM mtl.users where username = '"+name+"' and password = '"+pass+"';");
			if (rs.next()){
				user.add(rs.getString(8));	
				user.add(rs.getString(3));
				user.add(rs.getString(4));
			return user;
			}
			else {
				 user.add("1");
				 return user;
			}
		
		}
  
		catch (Exception ex )
		{
	  ex.printStackTrace();
		}
		 user.add("1");
		 return user;
	}
	

}
